//
//  KLBookTranslatorDAO.m
//  KLBookStore
//
//  Created by apple on 2017/10/15.
//  Copyright © 2017年 NetEaseExam. All rights reserved.
//

#import "KLBookTranslatorDAO.h"

@implementation KLBookTranslatorDAO

+ (long long)insertModel:(KLBookTranslator *)translator withDataBase:(FMDatabase *)db {
    
    BOOL success = [db executeUpdate:@"insert into 'TB_BOOK_TRANSLATOR'  (bookId, name) values (?,?)",@(translator.bookId),translator.name];
    
    if (success) {
        return [db lastInsertRowId];
    } else {
        return 0;
    }
}

+ (NSArray<KLBookTranslator *> *)queryModelById:(long long)localId withDataBase:(FMDatabase *)db {
    NSMutableArray *results = [@[] mutableCopy];
    
    FMResultSet *resultSet = [db executeQuery:@"select * from 'TB_BOOK_TRANSLATOR' where bookId = ?", @(localId)];
    
    while ([resultSet next]) {
        KLBookTranslator *entity = [[KLBookTranslator alloc] initWithFMResultSet:resultSet];
        [results addObject:entity];
    }
    [resultSet close];
    return results;
}

+ (BOOL)deleteModelWithId:(long long)localId withDataBase:(FMDatabase *)db {
    BOOL success = [db executeUpdate:@"delete from 'TB_BOOK_TRANSLATOR' where bookId = ?",@(localId)];
    return success;
}

@end
